package cn.edu.jxust.common.domain.web.api.enterprise;

import cn.edu.jxust.common.domain.valobj.EnterpriseVo;
import cn.edu.jxust.common.response.Result;
import cn.edu.jxust.core.infrastructure.util.Const;
import org.apache.shiro.authz.annotation.Logical;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.apache.shiro.authz.annotation.RequiresRoles;
import org.springframework.validation.BindingResult;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import javax.servlet.http.HttpServletRequest;

/**
 * @author QiuKangming
 * @version 1.0
 * @description
 * @since 2020/09/15 14:55
 */
@RequestMapping("/api/enterprise")
public interface IEnterpriseController {

    /**
     * 增加企业信息
     * @param enterpriseVo 企业视图对象
     * @param result 绑定对象
     * @return Result
     */
    @PostMapping
    @RequiresPermissions("enterprise:add")
    Result addEnterprise(@RequestBody @Validated EnterpriseVo enterpriseVo, BindingResult result);

    /**
     * 根据 id 删除企业信息
     * @param id 企业id
     * @return Result
     */
    @DeleteMapping("/{id}")
    @RequiresPermissions("enterprise:del")
    Result delEnterpriseById(@PathVariable("id") @Validated Integer id);

    /**
     * 修改企业信息
     * @param enterpriseVo 企业视图对象
     * @param result 绑定结果集
     * @return Result
     */
    @PutMapping
    @RequiresPermissions("enterprise:edit")
    Result modifyEnterprise(@RequestBody @Validated EnterpriseVo enterpriseVo, BindingResult result);

    /**
     * 分页查询企业信息或根据条件查询企业信息
     * 查询条见:
     *      区域id
     *      企业名字
     *      地址 (模糊查询)
     *      行业类型
     *      监管类型
     * @param page 第几页
     * @param size 一页几条数据
     * @param request 前端请求对象
     * @return Result
     */
    @GetMapping
    @RequiresPermissions("enterprise:list")
    Result listEnterpriseOrQuality(@RequestParam(value = "page", defaultValue = Const.DEFAULT_PAGE_NUMBER) Integer page,
                                   @RequestParam(value = "size", defaultValue = Const.DEFAULT_PAGE_SIZE) Integer size,
                                   HttpServletRequest request);

    /**
     * 根据区域id查询企业列表
     * @param areaId 区域id号
     * @return Result
     */
    @GetMapping("/list/{areaId}")
    @RequiresRoles(value = { Const.SUPER_ADMIN, Const.BUREAU_ADMIN, Const.DISTRICT_ADMIN }, logical = Logical.OR)
    @RequiresPermissions("enterprise:list")
    Result getEnterpriseListByAreaId(@PathVariable("areaId") Integer areaId);

}
